Skip to content

Conversation

@aitaider1u
Copy link

Hibernate queries must be paginated to avoid …
Issue link :

@github-actions
Copy link

This PR has been automatically marked as stale because it has no activity for 30 days.
Please add a comment if you want to keep the issue open. Thank you for your contributions!

@github-actions github-actions bot added the stale label Jun 21, 2025
@dedece35 dedece35 requested a review from Copilot July 5, 2025 21:41
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new Sonar rule (GCI1111) that enforces pagination on Hibernate queries to prevent excessive data loading.

  • Adds the DataInHibernateMustBePaginated rule implementation
  • Provides unit and integration tests for compliant and non-compliant cases
  • Registers the rule in the plugin registrar and updates the Sonar profile; bumps the rules-specifications version

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/main/java/org/greencodeinitiative/creedengo/java/checks/DataInHibernateMustBePaginated.java New rule checking repository methods return paged collections
src/test/java/org/greencodeinitiative/creedengo/java/checks/DataInHibernateMustBePaginatedTest.java Unit tests for issue detection and no-issue scenarios
src/test/files/DataInHibernateMustBePaginated.java Test case triggering rule violations
src/test/files/DataInHibernateMustBePaginatedNoIssue.java Test case demonstrating acceptable pagination usage
src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java Integration tests added for GCI1111
src/main/resources/org/greencodeinitiative/creedengo/java/creedengo_way_profile.json Sonar profile updated with new rule key
src/main/java/org/greencodeinitiative/creedengo/java/JavaCheckRegistrar.java Plugin registrar updated to include the new rule
pom.xml Updated creedengo-rules-specifications.version to 1.0-SNAPSHOT
Comments suppressed due to low confidence (3)

src/main/java/org/greencodeinitiative/creedengo/java/checks/DataInHibernateMustBePaginated.java:91

  • The method name retrournAllData contains a typo and is unclear; consider renaming it to returnsAllData or isReturningAllData for clarity.
    public boolean retrournAllData(String returnType) {

src/main/java/org/greencodeinitiative/creedengo/java/checks/DataInHibernateMustBePaginated.java:65

  • [nitpick] The method name extracted is non-descriptive; consider renaming it to something like checkPaginationRequirement or reportMissingPagination.
    private void extracted(boolean returnsAllData, boolean hasPaginationParam, MethodTree methodTree, boolean usesQueryAnnotation) {

pom.xml:81

  • The creedengo-rules-specifications version was changed from 2.2.2 to 1.0-SNAPSHOT, which appears to be a downgrade; please confirm this is intentional to avoid compatibility issues.
        <creedengo-rules-specifications.version>1.0-SNAPSHOT</creedengo-rules-specifications.version>

Comment on lines +14 to +25
import java.util.Collections;
import java.util.List;

import org.sonar.check.Rule;
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
import org.sonar.plugins.java.api.tree.*;
import org.sonar.plugins.java.api.semantic.Symbol;
import org.sonar.plugins.java.api.semantic.Type;

import java.util.Collections;
import java.util.List;

Copy link

Copilot AI Jul 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Duplicate import of Collections detected; remove redundant imports (Collections and List) to clean up the imports section.

Suggested change
import java.util.Collections;
import java.util.List;
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
import org.sonar.plugins.java.api.tree.*;
import org.sonar.plugins.java.api.semantic.Symbol;
import org.sonar.plugins.java.api.semantic.Type;
import java.util.Collections;
import java.util.List;
import org.sonar.check.Rule;
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
import org.sonar.plugins.java.api.tree.*;
import org.sonar.plugins.java.api.semantic.Symbol;
import org.sonar.plugins.java.api.semantic.Type;

Copilot uses AI. Check for mistakes.
Comment on lines +67 to +72
if (returnsAllData && !hasPaginationParam) {
reportIssue(methodTree.simpleName(),
MESSAGE);
} else if (usesQueryAnnotation && returnsAllData && !hasPaginationParam) {
reportIssue(methodTree.simpleName(),
MESSAGE);
Copy link

Copilot AI Jul 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This else if condition is redundant because the previous if (returnsAllData && !hasPaginationParam) already covers the same logic; you can simplify by merging these branches.

Suggested change
if (returnsAllData && !hasPaginationParam) {
reportIssue(methodTree.simpleName(),
MESSAGE);
} else if (usesQueryAnnotation && returnsAllData && !hasPaginationParam) {
reportIssue(methodTree.simpleName(),
MESSAGE);
if ((returnsAllData && !hasPaginationParam) || (usesQueryAnnotation && returnsAllData && !hasPaginationParam)) {
reportIssue(methodTree.simpleName(),
MESSAGE);

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please correct this Copilot feedback


private static boolean isUsesQueryAnnotation(MethodTree methodTree) {
boolean usesQueryAnnotation = methodTree.modifiers().annotations().stream()
.anyMatch(ann -> ann.annotationType().toString().equals("Query"));
Copy link

Copilot AI Jul 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using annotationType().toString() may not reliably match fully qualified annotation names; consider checking the annotation's symbol (e.g., ann.annotationType().symbolType().fullyQualifiedName()) for robustness.

Suggested change
.anyMatch(ann -> ann.annotationType().toString().equals("Query"));
.anyMatch(ann -> "org.springframework.data.jpa.repository.Query".equals(ann.annotationType().symbolType().fullyQualifiedName()));

Copilot uses AI. Check for mistakes.
}


// Récupérer le nom de la méthode
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please translate comments to english

String returnType = methodTree.returnType().symbolType().toString();

// Vérifier s’il retourne une collection entière (sans pagination)
boolean returnsAllData = retrournAllData(returnType);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo error in method name (please use something like "isToto" because it returns a boolean

return usesQueryAnnotation;
}

private static boolean isHasPaginationParam(MethodTree methodTree) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please delete "is" prefix because "has" prefix is enough


}

private void extracted(boolean returnsAllData, boolean hasPaginationParam, MethodTree methodTree, boolean usesQueryAnnotation) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use a method name more explicit ... when I read the method name I must understand what it will do

Comment on lines +67 to +72
if (returnsAllData && !hasPaginationParam) {
reportIssue(methodTree.simpleName(),
MESSAGE);
} else if (usesQueryAnnotation && returnsAllData && !hasPaginationParam) {
reportIssue(methodTree.simpleName(),
MESSAGE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please correct this Copilot feedback

@dedece35 dedece35 assigned dedece35 and aitaider1u and unassigned JulienPlanque Jul 5, 2025
@github-actions github-actions bot removed the stale label Jul 6, 2025
@github-actions
Copy link

This PR has been automatically marked as stale because it has no activity for 30 days.
Please add a comment if you want to keep the issue open. Thank you for your contributions!

@github-actions github-actions bot added the stale label Aug 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants